#include "logger.hpp"
#include <iostream>
#include "spdlog/sinks/stdout_color_sinks.h"
#include "spdlog/sinks/basic_file_sink.h"

using namespace std;

std::shared_ptr<spdlog::logger> Logger::__coreLogger;
std::shared_ptr<spdlog::logger> Logger::__clientLogger;

mb Logger::enabled = 1u;
void Logger::Log(char const *str)
{
    if (!Logger::enabled)
    {
        return;
    }
    cout << str << endl;
}

void Logger::init()
{
    std::vector<spdlog::sink_ptr> logSinks;
    logSinks.emplace_back(std::make_shared<spdlog::sinks::stdout_color_sink_mt>());
    logSinks.emplace_back(std::make_shared<spdlog::sinks::basic_file_sink_mt>("footman.log", true));

    logSinks[0]->set_pattern("%^[%T] %n: %v%$");
    logSinks[1]->set_pattern("[%T] [%l] %n: %v");

    __coreLogger = std::make_shared<spdlog::logger>("FOOTMAN", begin(logSinks), end(logSinks));
    spdlog::register_logger(__coreLogger);
    __coreLogger->set_level(spdlog::level::trace);
    __coreLogger->flush_on(spdlog::level::trace);

    __clientLogger = std::make_shared<spdlog::logger>("APP", begin(logSinks), end(logSinks));
    spdlog::register_logger(__clientLogger);
    __clientLogger->set_level(spdlog::level::trace);
    __clientLogger->flush_on(spdlog::level::trace);
}